package archive.others;

/**
 * https://www.zhihu.com/question/27683900
 */
class YinYangPuzzle {

    public static void main(String[] args) {
        YinYang yin = makeYin();
        yin.invoke(yin);
    }

    private static YinYang makeYin() {
        return yinYang -> {
            System.out.print("@");
            YinYang yang = makeYang(yinYang);
            return yang.invoke(yang);
        };
    }

    private static YinYang makeYang(YinYang yin) {
        return yinYang -> {
            System.out.print("*");
            return yin.invoke(yinYang);
        };
    }

    @FunctionalInterface
    private interface YinYang {
        YinYang invoke(YinYang yinYang);
    }
}
